package api

import (
	"alertmanagerWebhook/common"
	"alertmanagerWebhook/config"
	"alertmanagerWebhook/global"
	"net/http"

	"github.com/gin-gonic/gin"
)

// SendToQywechat handles sending notifications to WeChat.
func SendToQywechat(c *gin.Context, notification config.Notification) {
	global.Logger.Info("进入企业微信告警通知渠道")
	if err := common.SendWeChatNotification(notification); err != nil {
		global.Logger.Errorf("Failed to send WeChat notification: %v", err)
		c.JSON(http.StatusInternalServerError, gin.H{
			"error":  "failed to send notification",
			"detail": err.Error(),
		})
		return
	}
	global.Logger.Infof("wechat sent successfully ")
	c.JSON(http.StatusOK, gin.H{"status": "success"})
}
